import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

// import { h } from 'vue';
import { DictEnum } from '@vben/constants';
// import { VbenIcon } from '@vben/icons';
import { getPopupContainer } from '@vben/utils';

// import { Tag } from 'ant-design-vue';
// import { z } from '#/adapter/form';
import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Select',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.DATA_SOURCE_TYPE, true),
    },
    fieldName: 'type',
    label: '来源类型',
  },
  {
    component: 'Input',
    fieldName: 'name',
    label: '来源名称',
  },
  {
    component: 'Select',
    componentProps: {
      options: getDictOptions(DictEnum.SYS_NORMAL_DISABLE),
    },
    fieldName: 'status',
    label: '状态',
  },
];

export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '来源类型',
    field: 'type',
    slots: {
      default: ({ row }) => {
        return renderDict(row.type, DictEnum.DATA_SOURCE_TYPE);
      },
    },
  },
  {
    title: '来源名称',
    field: 'name',
  },
  {
    title: '显示顺序',
    field: 'sort',
  },
  {
    title: '状态',
    field: 'status',
    slots: { default: 'status' },
  },
  {
    title: '备注',
    field: 'remark',
    showOverflow: true,
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 180,
  },
];

export const drawerSchema: FormSchemaGetter = () => [
  {
    label: '来源ID',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: '来源类型',
    fieldName: 'type',
    component: 'Select',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.DATA_SOURCE_TYPE, true),
    },
    rules: 'selectRequired',
  },
  {
    label: '来源用途',
    fieldName: 'purpose',
    component: 'Input',
    help: '将自动生成来源名称，格式为YYYYMMdd-用途',
    rules: 'required',
  },
  // {
  //   label: '来源名称',
  //   fieldName: 'name',
  //   component: 'Input',
  //   rules: 'required',
  // },
  {
    component: 'InputNumber',
    fieldName: 'sort',
    help: '排序, 数字越小越靠前',
    label: '显示排序',
    defaultValue: 0,
    rules: 'required',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      buttonStyle: 'solid',
      options: getDictOptions(DictEnum.SYS_NORMAL_DISABLE),
      optionType: 'button',
    },
    defaultValue: '0',
    fieldName: 'status',
    label: '状态',
    rules: 'selectRequired',
  },
  {
    label: '备注',
    fieldName: 'remark',
    component: 'Textarea',
    componentProps: {
      autoSize: { minRows: 3 },
    },
  },
];

export const detailsSchema: DetailsModalSchemaGetter = () => [
  {
    label: '来源名称',
    fieldName: 'name',
    copy: true,
  },
  {
    label: '来源类型',
    fieldName: 'type',
    dictEnum: DictEnum.DATA_SOURCE_TYPE,
  },
  {
    label: '排序',
    fieldName: 'sort',
  },
  {
    label: '状态',
    fieldName: 'status',
    dictEnum: DictEnum.SYS_NORMAL_DISABLE,
  },
  {
    label: '备注',
    fieldName: 'remark',
    textWrap: true,
  },
];
